﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Demo1
{

    public class MapHandle
    {
        static Random _Random = new Random();
        public uint _ID;
        public float _X;
        public float _Y;
        public float _Z;

        public float _Diameter;

        public MapHandle()
        {
            _X = _Random.Next(-500,500);
            _Y = _Random.Next(-500, 500);
            _Z = _Random.Next(-500, 500);
            _Diameter = _Random.Next(10,20);
        }
    }

    //public class oCreate : Operation
    //{
    //    public uint _ID;
    //}


    //public class oCollision : Operation
    //{
    //    public uint ID;
    //    public uint CollisionID = 0;
    //}

    public class MapManager 
    {
        static public MapManager I = new MapManager();
        
        Dictionary<uint, MapHandle> _MapObjectList = new Dictionary<uint, MapHandle>();

        public uint _GenerateID = 0;

        public MapHandle Create()
        {
            MapHandle mapObject = new MapHandle();

            mapObject._ID = ++_GenerateID;

            _MapObjectList.Add(mapObject._ID, mapObject);

            return mapObject;
            
        }

        public void Destroy(uint id)
        {
            _MapObjectList.Remove(id);
        }

        public MapHandle CollisionCheck(MapHandle mapHandle)
        {
            
            foreach (MapHandle m1 in _MapObjectList.Values)
            {

                if (m1 != mapHandle)
                {
                    double dist = Math.Sqrt(Math.Pow((m1._X - mapHandle._X), 2) + Math.Pow((m1._Y - mapHandle._Y), 2) + Math.Pow((m1._Z - mapHandle._Z), 2));
                    if (dist < (m1._Diameter + mapHandle._Diameter))
                        return m1;
                }

            }
            return null;
        }

        public void MoveTo(MapHandle mapHandle, double x, double y)
        {
            //MapHandle m2 = _MapObjectList[uid];
            if (mapHandle._X < x)
                mapHandle._X--;
            else
                mapHandle._X++;

            if (mapHandle._Y < y)
                mapHandle._Y--;
            else
                mapHandle._Y++;
        }
    }
}
